package com.dingding.manager.modules._example.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;
import javax.validation.Valid;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.dingding.manager.common.exception.BussinessException;
import com.dingding.manager.common.exception.enums.BizExceptionEnum;
import com.dingding.manager.modules._example.dto.ReqUser;
import com.dingding.manager.modules._example.service.PlayerService;

//@RestController // 让控制器默认使用消息转换，使用消息转换就会让控制器中的方法返回的对象经过消息转化，返回客户端期望的消息类型
@Controller
@RequestMapping("/player")
public class PlayerController {

//	@Resource
	private PlayerService userService;

	@RequestMapping(method = RequestMethod.GET, path = "/getOrder")
	public String fff(@Valid ReqUser user, BindingResult result,HttpServletRequest request) throws IOException, ServletException {
		//----------------------------↑↑--------------------↑↑   @BindingResult需要挨着需要验证参数
		// 验证请求参数
		if (result.hasErrors()) {
			throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
		}
		
		
		Part part = request.getPart("file");
		part.getInputStream();
		
		
		return "index";
	}

	@RequestMapping(method = RequestMethod.GET, path = "/getUser")
	@ResponseStatus(HttpStatus.CREATED)
	public @ResponseBody List<Object> getUser() {
		
		ArrayList<Object> arrayList = new ArrayList<>();
		arrayList.add(123);
		arrayList.add(123);
		arrayList.add(123);
		arrayList.add(123);
		arrayList.add(123);
		return arrayList;
	}

	@RequestMapping(method = RequestMethod.GET, path = "/login")
	public String login(HttpSession httpSession) {
		httpSession.setAttribute("user", "123");
		return "index";
	}

}